﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;

namespace CompilerDLL.LexicalAnalysis
{
    public class BaseLexical
    {
        #region 变量 
        protected ModelTokenType modelTokenType;

        #region 变量

        /// <summary>
        /// 依次读入的字符
        /// </summary>
        protected  char ch;

        /// <summary>
        /// 待生成的单词符号
        /// </summary>
        protected string strToken;

        /// <summary>
        /// 单词符号列表
        /// </summary>
        protected  ArrayList arrayTokens;

        /// <summary>
        /// 源代码字符串的字符列表
        /// </summary>
        protected char[] sourceCodeChars;

        /// <summary>
        /// 单词符号指示器
        /// </summary>
        protected int tokenIndexer = 0;

       
        #endregion 

        #endregion 

      

        #region 得到下一个字符
        /// <summary>
        /// 得到下一个字符
        /// </summary>
        /// <param name="sourceCodeChars"></param>
        /// <param name="i"></param>
        /// <returns></returns>
        protected char GetChar(char[] sourceCodeChars, int i)
        {
            this.ch = sourceCodeChars[i];
            return this.ch;

        }
        #endregion

        #region 判断是否为字符
        /// <summary>
        /// 判断是否为字符
        /// </summary>
        /// <param name="ch"></param>
        /// <returns></returns>
        protected bool IsLetter(char ch)
        {
            if (((ch <= 'z') && (ch >= 'a')) || ((ch <= 'Z') && (ch >= 'A')))
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        #endregion

        #region 判断是否为数字
        /// <summary>
        /// 判断是否为数字
        /// </summary>
        /// <param name="ch"></param>
        /// <returns></returns>
        protected bool IsDigit(char ch)
        {
            if ((ch <= '9') && (ch >= '0'))
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        #endregion

        #region 判断是否为运算符
        /// <summary>
        /// 判断是否为运算符
        /// </summary>
        /// <param name="ch"></param>
        /// <returns></returns>
        protected bool IsOporator(char ch)
        {
            if (ch == '+'
                        || ch == '-'
                        || ch == '*'
                        || ch == '/'
                        || ch == '='
                        || ch == '<'
                        || ch == '>'
                        || ch == '!')
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        #endregion

        #region 单词指针回退一步时所指向的字符
        /// <summary>
        /// 单词指针回退一步时所指向的字符
        /// </summary>
        protected void Retract()
        {
            this.tokenIndexer --;
            this.ch  = this.GetChar(this.sourceCodeChars,this.tokenIndexer);
        }
        #endregion
    }
}
